﻿using Fetches.Fetch.Factory;
using FetchesDeploy.Distributed.Factory;
using Microsoft.AspNetCore.Mvc;

namespace FetchesDeploy.ScalableFactoryUnit.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class SystemController : ControllerBase
    {
        [HttpGet("restart")]
        public ActionResult Restart()
        {
            FetchFactoryUnit.Instance().Run();
            return Redirect("/");
        }

        [HttpGet("factory_config")]
        public FactoryConfig GetFactoryConfig()
        {
            return LocalFetchFactory.CurrentFactoryConfig;
        }

        [HttpPost("factory_config")]
        public string SetFactoryConfig(FactoryConfig config)
        {
            FetchFactoryUnit.Instance().ChangeFactoryConfig(config);
            return "success";
        }
    }
}
